package com.cyq.day13.knightgame;

import java.util.Scanner;

public class Game {
    Scanner scanner = new Scanner(System.in);
    Map map = new Map();
    int playerPos1;
    int playerPos2;
    String[] goAndStop = new String[2];
    String[] playerName = new String[2];
    int round =1;

    public void init() {
        map = new Map();
        map.creatMap();
        playerPos1 = 0;
        playerPos2 = 0;
        goAndStop[0] = "on";
        goAndStop[1] = "on";
    }

    public void biginMap() {
        System.out.println("              " + "骑士飞行棋" + "              ");
        System.out.println("              " + "两人对战" + "              ");
        System.out.println("请选择角色：1.德玛西亚之力 2.诺克萨斯之手 3.离群之刺 4.虚空行者");
        heroPick();
        System.out.println("*****************************************");
        System.out.println("                Game Start               ");
        System.out.println("*****************************************");
        System.out.println("^_^" + playerName[0] + "的士兵：A");
        System.out.println("^_^" + playerName[1] + "的士兵: B");
        System.out.println("图例：!! 暂停 xx轮盘 **地雷 ==隧道 ::普通");
        map.showBeginMap();
        System.out.println();
    }

    public void gameInfo() {
        while (true) {
            System.out.println("Round"+round);
            int rollNumber = (int) (Math.random() * 5 + 1);
            if (round % 2 == 1) {
                System.out.print(playerName[0] + ",请您按任意字母键回车启动掷骰子");
                String nomeaning = scanner.next();
                System.out.println("-----------------");
                System.out.println("骰子数；" + rollNumber);
                playerPos1 += rollNumber;
                if (goAndStop[0].equals("on")){
                    if (playerPos1==playerPos2){
                        playerPos2=0;
                        System.out.println("泰山压顶给我回起点");
                    }
                    if (playerPos1==map.luckyTurn[0]||playerPos1==map.luckyTurn[1]||playerPos1==map.luckyTurn[2]||playerPos1==map.luckyTurn[3]||playerPos1==map.luckyTurn[4]){
                        System.out.println("------欢迎进入幸运轮盘------");
                        System.out.println("请选择一种运气:");
                        System.out.println("1.交换位置   2.轰炸");
                        int input=scanner.nextInt();
                        if (input==1){
                            int temp=0;
                            temp=playerPos2;
                            playerPos2=playerPos1;
                            playerPos1=temp;
                        }
                        if (input==2){
                            playerPos2-=6;
                        }
                    }
                    if (playerPos1==map.landMine[0]||playerPos1==map.landMine[1]||playerPos1==map.landMine[2]||playerPos1==map.landMine[3]||playerPos1==map.landMine[4]||playerPos1==map.landMine[5]||playerPos1==map.landMine[6]||playerPos1==map.landMine[7]||playerPos1==map.landMine[8]){
                        playerPos1-=6;
                        if (playerPos1<0){
                            playerPos1=0;
                        }
                        System.out.println("踩中地雷！！退后6格");
                    }
                    if (playerPos1==map.pause[0]||playerPos1==map.pause[1]||playerPos1==map.pause[2]||playerPos1==map.pause[3]){
                        goAndStop[0]="off";
                        System.out.println("踩到暂停键！！下轮没你了！");
                    }
                    if (playerPos1==map.timeTunnel[0]||playerPos1==map.timeTunnel[1]||playerPos1==map.timeTunnel[2]||playerPos1==map.timeTunnel[3]||playerPos1==map.timeTunnel[4]||playerPos1==map.timeTunnel[5]||playerPos1==map.timeTunnel[6]){
                        playerPos1+=10;
                        System.out.println("偶遇时光隧道！！前进10格");
                    }
                }else{
                    System.out.println("此轮停掷！");
                    playerPos1-=rollNumber;
                    goAndStop[0]="on";
                }
            } else {
                System.out.print(playerName[1] + ",请您按任意字母键回车启动掷骰子");
                String nomeaning = scanner.next();
                System.out.println("-----------------");
                System.out.println("骰子数；" + rollNumber);
                playerPos2 += rollNumber;
                if (goAndStop[1].equals("on")){
                    if (playerPos1==playerPos2){
                        playerPos1=0;
                        System.out.println("泰山压顶给我回起点");
                    }
                    if (playerPos2==map.luckyTurn[0]||playerPos2==map.luckyTurn[1]||playerPos2==map.luckyTurn[2]||playerPos2==map.luckyTurn[3]||playerPos2==map.luckyTurn[4]){
                        System.out.println("------欢迎进入幸运轮盘------");
                        System.out.println("请选择一种运气:");
                        System.out.println("1.交换位置   2.轰炸");
                        int input=scanner.nextInt();
                        if (input==1){
                            int temp=0;
                            temp=playerPos2;
                            playerPos2=playerPos1;
                            playerPos1=temp;
                        }
                        if (input==2){
                            playerPos1-=6;
                        }
                    }
                    if (playerPos2==map.landMine[0]||playerPos2==map.landMine[1]||playerPos2==map.landMine[2]||playerPos2==map.landMine[3]||playerPos2==map.landMine[4]||playerPos2==map.landMine[5]||playerPos2==map.landMine[6]||playerPos2==map.landMine[7]||playerPos2==map.landMine[8]){
                        playerPos2-=6;
                        if (playerPos2<0){
                            playerPos2=0;
                        }
                        System.out.println("踩中地雷！！退后6格");
                    }
                    if (playerPos2==map.pause[0]||playerPos2==map.pause[1]||playerPos2==map.pause[2]||playerPos2==map.pause[3]){
                        goAndStop[1]="off";
                        System.out.println("踩到暂停键！！下轮没你了！");
                    }
                    if (playerPos2==map.timeTunnel[0]||playerPos2==map.timeTunnel[1]||playerPos2==map.timeTunnel[2]||playerPos2==map.timeTunnel[3]||playerPos2==map.timeTunnel[4]||playerPos2==map.timeTunnel[5]||playerPos2==map.timeTunnel[6]){
                        playerPos2+=10;
                        System.out.println("偶遇时光隧道！！前进10格");
                    }
                }else{
                    System.out.println("此轮停掷！");
                    playerPos2-=rollNumber;
                    goAndStop[1]="on";
                }
            }
            if (playerPos1>=99){
                System.out.println("胜者是"+playerName[0]);
                System.exit(0);
            }
            if (playerPos2>=99){
                System.out.println("胜者是"+playerName[1]);
                System.exit(0);
            }
            System.out.println("您当前位置:" + playerPos1);
            System.out.println("对方当前位置:" + playerPos2);
            showMap(playerPos1,playerPos2);
            round++;
        }
    }
    public static void showMap(int position1,int position2){
    }
    public void heroPick() {
        System.out.print("请玩家1选择角色:");
        int input = scanner.nextInt();
        switch (input) {
            case 1:
                playerName[0] = "德玛西亚之力";
                break;
            case 2:
                playerName[0] = "诺克萨斯之手";
                break;
            case 3:
                playerName[0] = "离群之刺";
                break;
            case 4:
                playerName[0] = "虚空行者";
                break;
            default:
                System.out.println("输入错误");
                System.exit(0);
        }
        System.out.print("请玩家2选择角色:");
        int input1 = scanner.nextInt();
        switch (input1) {
            case 1:
                playerName[1] = "德玛西亚之力";
                break;
            case 2:
                playerName[1] = "诺克萨斯之手";
                break;
            case 3:
                playerName[1] = "离群之刺";
                break;
            case 4:
                playerName[1] = "虚空行者";
                break;
            default:
                System.out.println("输入错误");
        }
    }

}
